package com.sicheng.lc.周赛.分类.思维;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/16 14:19
 */
public class 含最多K个可整除元素的子数组 {

    //https://leetcode.cn/problems/k-divisible-elements-subarrays/

    public int countDistinct(int[] nums, int k, int p) {
        HashSet<List<Integer>> s = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            int cnt = 0;
            List<Integer> list = new ArrayList<>();
            for (int j = i; j < nums.length; j++) {
                if (nums[j] % p == 0) {
                    cnt++;
                }
                if (cnt > k)
                    break;
                list.add(nums[j]);
                s.add(new ArrayList<>(list));
            }
        }
        return s.size();
    }

    public static void main(String[] args) {

        含最多K个可整除元素的子数组 solution = new 含最多K个可整除元素的子数组();
        int[] nums = {2, 3, 3, 2, 2};
        int k = 2, p = 2;
        System.out.println(solution.countDistinct(nums, k, p));
    }
}
